﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Activation;
using PowerBooking.RSE.Domain.Factories;
using PowerBooking.RSE.IRepository;
using System.ServiceModel.Web;

namespace PowerBooking.RSE.Domain.Services
{
    /// <summary>
    /// 服务基类
    /// </summary>
    //[ServiceContract]
    //[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    //[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    public abstract class Service
    {
        private readonly Lazy<SpiderFactory> spiderFactory;
        private readonly Lazy<CityFactory> cityFactory;
        private readonly Lazy<FilterFactory> filterFactory;
        private readonly Lazy<RestaurantFactory> restaurantFactory;

        protected SpiderFactory SpiderFactory { get { return spiderFactory.Value; } }
        protected CityFactory CityFactory { get { return cityFactory.Value; } }
        protected FilterFactory FilterFactory { get { return filterFactory.Value; } }
        protected RestaurantFactory RestaurantFactory { get { return restaurantFactory.Value; } }

        protected IUnitOfWork UnitOfWork;

        public Service(IUnitOfWork unitOfWork)
        {
            UnitOfWork = unitOfWork;
            spiderFactory = new Lazy<SpiderFactory>(() => new SpiderFactory(unitOfWork));
            cityFactory = new Lazy<CityFactory>(() => new CityFactory(unitOfWork));
            filterFactory = new Lazy<FilterFactory>(() => new FilterFactory(unitOfWork));
            restaurantFactory = new Lazy<RestaurantFactory>(() => new RestaurantFactory(unitOfWork));

            WebOperationContext.Current.OutgoingResponse.Format = WebMessageFormat.Json;
            
        }
    }
}
